<!DOCTYPE html>
<html>
<head>
<head/>
<div th:include="base-libs :: base-libs" />
<div th:include="common/common-export :: common-export" />
<title>服务项管理</title>
<style type="text/css">
</style>
</head>
<script th:inline="javascript">
	/**用户信息*/
	var userInfo = [[${userInfo}]];
</script>
<script type="text/javascript">
$(function() {
//	$(this).registerManagerPage({
//		callback:
//	});
    enterToQuery(queryForm);
	$(this).getZydmCache({
		callback: initView
	})
});

function queryForm() {
	/**清空勾选*/
    selectionIds = [];
	$("#dgForm").datagrid("reload");
}

function initView(cacheData)
{
	var opt = {
			idField : "FWID",
			uniqueId: "FWID",
			striped : true,
			border:false,
			toolbar : "#dgFormToolbar",
			clickToSelect: true,
			columns : [[
				//{field: "checkStatus",checkbox: true}, 
				{
					field : "FWID",
					width: 150,
					align: "center",
					title : "服务项编号"
				},
				{
					field : "FWMC",
					width: 120,
					align: "center",
					title : "服务项名称"
				},
				{
					field : "FWNR",
					width: 120,
					align: "center",
					title : "服务内容",
					formatter : function(value, row, index){
						return "<span title='"+value+"'>"+value+"</span>";
					}
				},
				{
					field : "YLJGMC",
					width: 120,
					align: "center",
					title : "所属机构"
				},
				{
					field : "QYLBMC",
					width: 100,
					align: "center",
					title : "签约类别"
				},
				{
					field : "FWLBMC",
					width: 80,
					align: "center",
					title : "服务类别"
				},
				{
					field : "SFBZ",
					width: 120,
					align: "center",
					title : "收费标准",
					formatter : function(value, row, index){
						if(row["SFLX"] == "04"){
							value = getSflx(row["SFLX"]);
						}else{
							value = getSflx(row["SFLX"]) + "," + value + "元";
						}
						row.SFBZ2 = value; //用于导出
						return value;
					}
				},
				{
					field : "FWZTMC",
					align: "center",
					width: 70,
					title : "状态",
				},
				{
					field : "CJSJ",
					width: 90,
					align: "center",
					title : "创建日期",
					formatter : function(value, row, index){
						if(!StringUtils.isEmpty(value)){
							value = value.substr(0, 10);
							row.CJSJ = value;
						}
						return value;
					}
				},
				{
					field : "cz",
					width: 70,
					align: "center",
					title : "操作",
					formatter : operateFormatter
				}
			]]
			,pagination : true
			,fit: true
			,fitColumns: true
			,singleSelect: true
			,rownumbers: true
			,method : "post"
        	,url: contextRoot+"fwxx/queryPage.service"
			,onBeforeLoad:function(params)//加载之前回调 获取查询条件
			{
                var url = $(this).datagrid("options")["url"];
				/*URL不等空时再发送请求*/
                if (!StringUtils.isEmpty(url)) {
                    params["FWMC"] = $("#FWMC").val();
                    params["QYLB"] = $("#QYLB").val();
                    params["FWZT"] = $("#FWZT").val();
                    params["XZQHDM"] = userInfo["JGXZQHDM"];
                    return params;
                }
			}
		};
	$("#dgForm").datagrid(opt);

	/**更新服务项*/
	$("#btnUpdate").on("click", function(){
		var info = $("#dgForm").datagrid("getSelections");
		if(!validate(info)){
			$.QuickAlert.alertFail({content : "请选中服务项！"});
		}else if(info.length > 1){
			$.QuickAlert.alertFail({content : "请选中单条服务项！"});
		}else if(info[0]["FWZT"] != "0"){
			$.QuickAlert.alertFail({content : "启用服务项不可修改，请先停用服务项！"});
		}else{
			StoreCache.setCache("FWXX_INFO", info[0]);
			$.QuickUrlUtils.redirectUrl("manager.html");
		}
	});
	
	/**新建服务项*/
	$("#btnAdd").on("click", function(){
		$.QuickUrlUtils.redirectUrl("manager.html");
	});
	
	/**导出服务项*/
	$("#btnExport").on("click", function(){
		$("#JGXZQHDM").val(userInfo.JGXZQHDM);
		$("#exportForm").submit();
	});
	
}

/**操作格式化*/
function operateFormatter(value, row, index) {
	if(userInfo["PTJGID"] != row["XJJGID"] && (row["JGLB"]).substr(0,1) == "R"){
		return ($("#tableToolBar").html()).replace(/#index#/g,index);
	}
	var tool = $("#tableToolBarEnd").html();
	if(row["FWZT"] == "0"){
		tool = $("#tableToolBarStart").html();
	}
	return tool.replace(/#index#/g,index);
}


/**详细按钮*/
function detail(index){
	/**清除所有选择*/
	$("#dgForm").datagrid("clearSelections");
	/**选中当前行*/
	$("#dgForm").datagrid("selectRow", index);
	/**获取选中行数据*/
	var row = $("#dgForm").datagrid("getSelected", index);
	StoreCache.setCache("FWXX_INFO", row);
	$.QuickUrlUtils.redirectUrl("detail.html");
}
/**启用按钮*/
function start(index){
	/**清除所有选择*/
	$("#dgForm").datagrid("clearSelections");
	/**选中当前行*/
	$("#dgForm").datagrid("selectRow", index);
	/**获取选中行数据*/
	var row = $("#dgForm").datagrid("getSelected", index);
	$.QuickAlert.alertConfirm({content: "确认是否启用服务项？", callback: function(){
		$("#startForm").find(".FWID").val(row["FWID"]);
		$("#startForm").find(".FWZT").val("1");
		$.QuickRemote.AjaxFiledFormSubmit("startForm", function(result) { 
			var info = result["info"];
			if (result["state"]) {
				$.QuickAlert.alertNormal("启用成功！",{callback: function(){
					$("#btnQuery").trigger("click");
				}});
			} else {
				$.QuickAlert.alertFail({
					content : info["faultInfo"]
				});
			}
		});
	}});
}
/**停用按钮*/
function end(index){
	/**清除所有选择*/
	$("#dgForm").datagrid("clearSelections");
	/**选中当前行*/
	$("#dgForm").datagrid("selectRow", index);
	/**获取选中行数据*/
	var row = $("#dgForm").datagrid("getSelected", index);
	$.QuickAlert.alertConfirm({content: "确认是否停用服务项？", callback: function(){
		$("#stopForm").find(".FWID").val(row["FWID"]);
		$("#stopForm").find(".FWZT").val("0");
		$.QuickRemote.AjaxFiledFormSubmit("stopForm", function(result) { 
			var info = result["info"];
			if (result["state"]) {
				$.QuickAlert.alertNormal("停用成功！",{callback: function(){
					$("#btnQuery").trigger("click");
				}});
			} else {
				$.QuickAlert.alertFail({
					content : info["faultInfo"]
				});
			}
		});
	}});
}

/**查询按钮点击回调*/
function btnQueryHandler() {
	queryForm();
}

/**获取服务状态*/
// function getFwzt(fwzt){
// 	if(fwzt == "0"){
// 		fwzt = "停用";
// 	}
// 	else if(fwzt == "1"){
// 		fwzt = "启用";
// 	}
// 	return fwzt;
// }

/**获取收费类型*/
function getSflx(sflx){
	if(sflx == "01"){
		sflx = "按次收费";
	}
	else if(sflx == "02"){
		sflx = "按月收费";
	}
	else if(sflx == "03"){
		sflx = "按签约周期收费";
	}
	else if(sflx == "04"){
		sflx = "免费";
	}
	return sflx;
}

/**校验是否选中服务项*/
function validate(info){
	if(StringUtils.isEmpty(info)){
		return false;
	}else{
		return true;
	}
}
</script>

<body class="easyui-layout" data-options="fit:true">
	<div region="north" style="border: none; overflow: hidden;">
		<h4 class="h4-title" style="text-align:center;margin:0;padding:0; font-size: 18px;">
			服务项管理
		</h4>
	</div>
	<div region="center" style="border: none;">
		<div id="dgFormToolbar" style="background: white;">
			
			<form id="startForm" action="start">
				<div style="display: none;">
					<input class="FWID"  name="FWID" />
					<input class="FWZT"  name="FWZT" />
				</div>
			</form>
			<form id="stopForm" action="stop">
				<div style="display: none;">
					<input class="FWID"  name="FWID" />
					<input class="FWZT"  name="FWZT" />
				</div>
			</form>
			
			<!-- 导出:: onkeydown:取消js默认的回车提交表单的功能 -->
			<form id="exportForm" action="export.service" enctype="multipart/form-data" onkeydown="if(event.keyCode==13)return false;">
				<table class="form-table" style="margin:0;padding:0;">
					<tr>
						<td class="td-text">服务项名称：</td>
						<td class="td-content">
							<input type="hidden" name="XZQHDM" id="JGXZQHDM" />
						
							<input id="FWMC" name="FWMC" class="form-control" type="text"
								placeholder="服务项名称">
						</td>
						<td class="td-text">签约类别：</td>
						<td class="td-content">
							<select id="QYLB" name="QYLB" class="form-control " cacheTable="TB_ZY_QY_TYPE">
								<!-- <option value="">请选择</option>
								<option value="01">基本医疗</option>
								<option value="02">公共卫生</option>
								<option value="03">健康管理服务</option> -->
							</select>
						</td>
						<td class="td-text">状态：</td>
						<td class="td-content">
							<select id="FWZT" name="FWZT" class="form-control">
								<option value="">请选择</option>
								<option value="0">停用</option>
								<option value="1">启用</option>
							</select>
						</td>
						<td class="td-text" style="text-align:center;width:180px;">
							<button id="btnQuery" class="btn btn-info" type="button" onclick="btnQueryHandler()">查询</button>
							<button id="btnExport" class="btn-info" type="button" >导出</button>
						</td>
					</tr>
				</table>
			</form>
			<div style="margin:10px 10px auto 0px;">
				<button id="btnAdd" class="btn-info" type="button">新建服务项</button>
				<button id="btnUpdate" class="btn-info" type="button">修改服务项</button>
			</div>
		</div>
		<div class="easyui-layout" style="border: none;" fit="true">
			<div region="center" style="border: none;">
				<table id="dgForm">
				</table>
			</div>
		</div>
	</div>
</body>
<script type="text/html" id="tableToolBar">
<a class="detail tableToolBarBtn" href="javascript:detail(#index#)" title="详细">详细</a>
</script>
<script type="text/html" id="tableToolBarStart">
<a class="detail tableToolBarBtn" href="javascript:detail(#index#)" title="详细">详细</a>
<a class="start tableToolBarBtn" href="javascript:void(0)" title="启用" onclick="start(#index#)">启用</a>
</script>
<script type="text/html" id="tableToolBarEnd">
<a class="detail tableToolBarBtn" href="javascript:detail(#index#)" title="详细">详细</a>
<a class="stop tableToolBarBtn" href="javascript:void(0)" title="停用" onclick="end(#index#)">停用</a>
</script>
</html>



